package com.lyb.Security;

import com.lyb.pojo.User;
import com.lyb.services.UserService;
import com.lyb.services.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    UserService userService;
    public UserDetails loadUserByUsername(String name){
        User user = userService.getUserByName(name);
        if(Objects.isNull(user)){
            throw new RuntimeException("用户不存在");
        }
        List<String> list = new ArrayList<>(Arrays.asList("admin"));
        return new LoginUser(user,list);
    }
}
